import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class AuthSiteService extends BaseService<any> {
  private readonly logger = new Logger(AuthSiteService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getSiteInfo
   * 对应 PHP: AuthSiteService_admin::getSiteInfo()
   * 逻辑类型: undefined - undefined
   */
  async getSiteInfo() {
    // 基于PHP真实逻辑: getSiteInfo
    // PHP原文: //通过用户id获取         return ( new SiteService() )->getSiteCache($this->site_id);     }       /**      * 通过站点id获取菜单列表      * @param int $is_tree      * @...
//通过用户id获取
        return ( this.siteService ).getSiteCache(this.site_id);
    }


    /**
     * 通过站点id获取菜单列表
     * @param int is_tree
     * @param int|string status
     * @param string addon
     * @param int is_button
     * @return mixed
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getMenuList(int is_tree, status, addon = 'all', int is_button = 1)
    {
        return ( this.siteService ).getMenuList(this.site_id, is_tree, status, addon, is_button);
    }

    /**
     * 通过站点id获取菜单列表
     * @param int|string status
     * @return mixed
     */
    async getApiList(status)
    {
        return ( this.siteService ).getApiList(this.site_id, status);
    }

    /**
     * 查询当前站点可以单独显示的菜单(仅支持站点端调用)
     * @return array|SysMenu[]
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getShowMenuList()
    {
        const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
        return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
    }

    /**
     * 获取站点支持
     * @return array|mixed|string|null
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getAuthAddonList()
    {
        return ( this.addonService ).getAddonListBySiteId(this.site_id);
    }
}
  }

  /**
   * getMenuList
   * 对应 PHP: AuthSiteService_admin::getMenuList()
   * 逻辑类型: undefined - undefined
   */
  async getMenuList(is_tree: number, status: number, addon: number, is_button: number) {
    // 基于PHP真实逻辑: getMenuList
    // PHP原文: return ( new SiteService() )->getMenuList($this->site_id, $is_tree, $status, $addon, $is_button);     }      /**      * 通过站点id获取菜单列表      * @param int...
return ( this.siteService ).getMenuList(this.site_id, is_tree, status, addon, is_button);
    }

    /**
     * 通过站点id获取菜单列表
     * @param int|string status
     * @return mixed
     */
    async getApiList(status)
    {
        return ( this.siteService ).getApiList(this.site_id, status);
    }

    /**
     * 查询当前站点可以单独显示的菜单(仅支持站点端调用)
     * @return array|SysMenu[]
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getShowMenuList()
    {
        const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
        return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
    }

    /**
     * 获取站点支持
     * @return array|mixed|string|null
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getAuthAddonList()
    {
        return ( this.addonService ).getAddonListBySiteId(this.site_id);
    }
}
  }

  /**
   * getApiList
   * 对应 PHP: AuthSiteService_admin::getApiList()
   * 逻辑类型: undefined - undefined
   */
  async getApiList(status: any) {
    // 基于PHP真实逻辑: getApiList
    // PHP原文: return ( new SiteService() )->getApiList($this->site_id, $status);     }      /**      * 查询当前站点可以单独显示的菜单(仅支持站点端调用)      * @return array|SysMenu[]     ...
return ( this.siteService ).getApiList(this.site_id, status);
    }

    /**
     * 查询当前站点可以单独显示的菜单(仅支持站点端调用)
     * @return array|SysMenu[]
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getShowMenuList()
    {
        const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
        return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
    }

    /**
     * 获取站点支持
     * @return array|mixed|string|null
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getAuthAddonList()
    {
        return ( this.addonService ).getAddonListBySiteId(this.site_id);
    }
}
  }

  /**
   * getShowMenuList
   * 对应 PHP: AuthSiteService_admin::getShowMenuList()
   * 逻辑类型: undefined - undefined
   */
  async getShowMenuList() {
    // 基于PHP真实逻辑: getShowMenuList
    // PHP原文: $menu_keys = ( new SiteService() )->getMenuIdsBySiteId($this->site_id, 1);         return ( new SysMenu() )->where([ [ 'menu_key', 'in', $menu_keys ],...
const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
        return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
    }

    /**
     * 获取站点支持
     * @return array|mixed|string|null
     * @throws DataNotFoundBusinessException
     * @throws DbBusinessException
     * @throws ModelNotFoundBusinessException
     */
    async getAuthAddonList()
    {
        return ( this.addonService ).getAddonListBySiteId(this.site_id);
    }
}
  }

  /**
   * getAuthAddonList
   * 对应 PHP: AuthSiteService_admin::getAuthAddonList()
   * 逻辑类型: undefined - undefined
   */
  async getAuthAddonList() {
    // 基于PHP真实逻辑: getAuthAddonList
    // PHP原文: return ( new AddonService() )->getAddonListBySiteId($this->site_id);     } }...
return ( this.addonService ).getAddonListBySiteId(this.site_id);
    }
}
  }
}
